{extend name="common:frm_base" /}
{block name="content"}
<style>
    .layui-input-inline{width:350px!important;}
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">绑定{if $type_id==0}站点{else /}服务队{/if}</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="{:url('site_team/handle')}" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">{if $type_id==0}站点名称{else /}服务队名称{/if}</label>
                    <div class="layui-input-inline" style="margin-left:20px;">
                        <input type="text" value="{$info.name|default=''}" disabled name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label" style="width:120px;">类型</label>-->
<!--                    <div class="layui-input-inline">-->
<!--                        <select name="type_id" lay-filter="aihao">-->
<!--                            <option value="0">站点</option>-->
<!--                            <option value="1">服务队</option>-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->
                {if $type_id==0}
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">归属站点</label>
                    <div class="layui-input-inline" style="margin-left:20px;">
                        <div id="role_id" class="xm-select-demo"></div>
                        <input type="hidden" name="sid" id="sid">
                    </div>
                </div>
                <script src="/static/admin/xm-select.js"></script>
                <script>
                    $(function() {
                        $.post("{:url('site_team/get_site')}", {}, function (res) {
                            var list = res.list;
                            var demo1 = xmSelect.render({
                                el: '#role_id',
                                filterable: true,
                                paging: true,
                                max: 1,
                                data: list,
                                on: function (e) {
                                    var arr = demo1.getValue();
                                    var str = '';
                                    for (var item in arr) {
                                        str += ',' + arr[item].value;
                                    }
                                    if (e.isAdd) {
                                        str += ',' + e.change[0].value;
                                    }
                                    str = str.substr(1);
                                    $('#sid').val(str);
                                }
                            });
                        }, 'json');
                    });
                </script>
                {else /}
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px;">归属服务队</label>
                    <div class="layui-input-inline" style="margin-left:20px;">
                        <div id="oid_id" class="xm-select-demo"></div>
                        <input type="hidden" name="oid" id="oid">
                    </div>
                </div>
                <script src="/static/admin/xm-select.js"></script>
                <script>
                    $(function() {
                        $.post("{:url('site_team/get_site_team')}", {}, function (res) {
                            var list = res.list;
                            var demo1 = xmSelect.render({
                                el: '#oid_id',
                                filterable: true,
                                paging: true,
                                max: 1,
                                data: list,
                                on: function (e) {
                                    var arr = demo1.getValue();
                                    var str = '';
                                    for (var item in arr) {
                                        str += ',' + arr[item].value;
                                    }
                                    if (e.isAdd) {
                                        str += ',' + e.change[0].value;
                                    }
                                    str = str.substr(1);
                                    $('#oid').val(str);
                                }
                            });
                        }, 'json');
                    });
                </script>
                {/if}
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
                </div>
                <div class="layui-form-item">
                    <input type="hidden" value="{if $type_id==0}bing{else /}edit{/if}" name="act" />
                    <input type="hidden" name="type_id" value="{$type_id}">
                    <input type="hidden" value="{$info['id']|default=''}" name="id" />
                    <div class="layui-input-block" style="margin-left:148px;">
                        <button class="layui-btn" lay-submit lay-filter="formSub">立即提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'upload'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form
            ,upload = layui.upload;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#begin_time'
            ,type: 'date'
        });
        form.on('select(aihao)', function(data){
            if(data.value==1){
                $('#site').addClass('layui-hide');
                $('#site_team').removeClass('layui-hide');
            }else{
                $('#site_team').addClass('layui-hide');
                $('#site').removeClass('layui-hide');
            }
        });
        form.on('submit(formSub)', function(data){
            if(data.field.sid==0){
               layer.alert('请选择站点');
               return false;
            }
            $.ajax({
                type: 'POST'
                ,url: data.form.action
                ,data: data.field
                ,dataType: 'json'
                ,success:function(res){
                    if (res.code == 0){
                        layer.alert("绑定成功",function(res){
                            window.location = '/admin/index/index';
                        });
                    } else{
                        layer.alert(res.msg);
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>
{/block}